﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

namespace School.UserCentents
{
    public partial class My_Centents1 : UserCheckPower
    {
        BLL.UserPic UserPic = new BLL.UserPic();
        BLL.Users Users = new BLL.Users();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = UserPic.GetAllList();
                DropDownList1.DataValueField = "ID";
                DropDownList1.DataTextField = "ImgName";
                DropDownList1.DataBind();

                Model.Users u = Users.GetModel(LoginUserId);
                lbID.Text = u.MembeLoginName;
                nickname.Value = u.MemberName;
                tel.Value = u.Phone;
                RadioButtonList1.SelectedValue = u.Sex.ToString();
                txtQQ.Text = u.QQ;
                txtaddress.Text = u.Address;
                txtContents.Text = u.Description;
                if (u.Birthday != null)
                {
                    txtBirthday.Text = DateTime.Parse(u.Birthday.ToString()).ToString("yyyy-MM-dd");
                }

                Model.UserPic c = UserPic.GetModel(int.Parse(u.Pic));
                Image1.ImageUrl = c.ImgURL;
                DropDownList1.SelectedValue = u.Pic;
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Model.UserPic u = UserPic.GetModel(int.Parse(DropDownList1.SelectedValue));
            Image1.ImageUrl = u.ImgURL;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Model.Users u = Users.GetModel(LoginUserId);
            u.MembeLoginName = lbID.Text;
            u.MemberName = nickname.Value;
            u.Phone = tel.Value;
            u.Sex = int.Parse(RadioButtonList1.SelectedValue);
            u.QQ = txtQQ.Text;
            u.Address = txtaddress.Text;
            u.Description = txtContents.Text;
            u.Pic = DropDownList1.SelectedValue;
            u.Birthday = DateTime.Parse(DateTime.Parse(txtBirthday.Text).ToString("yyyy-MM-dd"));
            Users.Update(u);
            ScriptHelper.AlertRedirect("修改成功！", "MyInf.aspx");
        }
    }
}